package com.nj.code;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:王亚栋
 * @Date:2022/5/9 22:39
 * @Version:1.0
 * 两数之和
 */
public class Test01 {
    public static void main(String[] args) {

        //输入 nums = {2,7,11,15} 输出：target = 9
       int[] nums = {3,7,11,15,2,6};
       int target =26;

        System.out.println(Arrays.toString(twoSum(nums, target)));
    }

    public static int[] twoSum(int[] nums,int target) {

        Map<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                if (i != j && nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return null;
    }
}
